<?php
namespace app\admin\controller;
use app\admin\model\Cate as CateModel;
class RbacGroup extends Common
{
    public function lit()
    {
    	$groupRes = db('rbac_group') -> select();
    	$this -> assign('groupRes',$groupRes);	
        return $this -> fetch();
    }
    public function add(){
    	if(request()->isPost()){
            $post = input('post.');
            $post['rules'] = implode(',', $post['rules']);
    		if(db('rbac_group') -> insert($post)){
    			$this -> success('添加栏目成功','lit');
    		}else{
    			$this -> error('添加栏目失败');
    		}
    	}
    	$RuleRes = db('rbac_rule') -> select();
    	$this -> assign('RuleRes',$RuleRes);
    	return $this -> fetch();
    }
    public function edit(){
    	if(request()->isPost()){
            $post = input('post.');
            $post['rules'] = implode(',', $post['rules']);
            if(db('rbac_group') -> update($post)){
                $this -> success('添加栏目成功','lit');
            }else{
                $this -> error('添加栏目失败');
            }
        }
    	$RuleRes = db('rbac_rule') -> select();
        $groupRes = db('rbac_group') -> find(input('id'));
        $groupRes['rules'] = explode(',',$groupRes['rules']);
        $this -> assign('RuleRes',$RuleRes);
        $this -> assign('groupRes',$groupRes);
    	return $this -> fetch();
    }
    public function del(){
    	$b = db('rbac_group') -> delete(input('id'));
    	if($b){
    		$this -> success('删除栏目成功','lit');
    	}else{
    		$this -> error('删除栏目失败');
    	}
    }
}
